﻿using System;

namespace Inspired.Euler
{
    /// <summary>
    /// If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
    /// The sum of these multiples is 23.
    /// 
    /// Find the sum of all the multiples of 3 or 5 below 1000.
    /// </summary>
    public static class Problem001
    {
        /// <summary>
        /// Add all the natural numbers below one thousand that are multiples of 3 or 5.
        /// </summary>
        [EulerProblem(1, Title = "Add all the natural numbers below one thousand that are multiples of 3 or 5.")]
        public static long Solve()
        {
            Func<int, int, long> divisibleBy = (target, number) =>
            {
                int p = target / number;
                return number * (p * (p + 1)) / 2;
            };

            return
                divisibleBy(999, 3) + 
                divisibleBy(999, 5) - 
                divisibleBy(999, 15);
        }
    }
}
